package dao

import (
	"CDSystem/v2/config"
	"context"
	"log"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

var MongoDB *mongo.Database
var LabelColl *mongo.Collection

func init() {
	log.Println("链接mongodb数据库......")
	option := options.Client().ApplyURI(config.Cfg.Database.MongodbUrl)
	client, err := mongo.Connect(context.TODO(), option)
	if err != nil {
		log.Println(err)
		return
	}
	err = client.Ping(context.TODO(), nil)
	if err != nil {
		log.Println(err)
		return
	}
	log.Println("mongodb链接成功")
	MongoDB = client.Database("cdsystem")
	LabelColl = MongoDB.Collection("labelset")
}
